﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Web.Configuration;

namespace HospitalSystem
{
    public partial class Report : System.Web.UI.Page
    {
        //public static List<string> y = new List<string>();
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {

            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            BindData();
        }

        protected void BindData()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection scon = new SqlConnection(constr);
            scon.Open();

            SqlCommand cmd = new SqlCommand("SELECT CID,FirstName,LastName FROM Person where CID=@text or FirstName=@text or Lastname=@text", scon);
            cmd.Parameters.AddWithValue("@text", TextBox1.Text);
            SqlDataReader reader = cmd.ExecuteReader();


            GridView1.DataSource = reader;
            GridView1.DataBind();
            scon.Close();
        }

        protected void BindDatadek()
        {
            SelectStat.Text = string.Empty;
            bool selectorChecked3 = false;
            string CCID = "";
            DataTable dt2 = new DataTable();
            dt2.Columns.Add("CID");
            dt2.Columns.Add("FirstName");
            dt2.Columns.Add("LastName");



            //   dt2.Columns.Add("note");
            foreach (GridViewRow row in GridView1.Rows)
            {
                RadioButton cb = (RadioButton)row.FindControl("CaseSelector3");
                if (cb != null && cb.Checked)
                {
                    selectorChecked3 = true;

                    DataRow dr2;
                    dr2 = dt2.NewRow();
                    string CID = GridView1.Rows[row.RowIndex].Cells[0].Text;
                    CCID = CID;
                    string FirstName = GridView1.Rows[row.RowIndex].Cells[1].Text;
                    string LastName = GridView1.Rows[row.RowIndex].Cells[2].Text;
                    SelectStat.Text += string.Format(CID);
                    Label2.Text = string.Format(FirstName);
                    Label3.Text = string.Format(LastName);
                    dt2.Rows.Add(CID, FirstName, LastName);


                }
            }
            SelectStat.Visible = selectorChecked3;
            Response.Redirect("Report2.aspx?IDStudent="+CCID);

        }
        protected void CaseSelector3_CheckedChanged(object sender, EventArgs e)
        {
            BindDatadek();
            // crepsnumber();
            // psnumbertolabel();
            sendsession();
            //Bindcase();

        }

        protected void sendsession()
        {
            Session.Clear();
            //Session["CID"] = SelectStat.Text;
            
        }


    }
}